<template>
  <div class="video-list-container">
    <div class="video-list-title" v-show="showTitle">
      {{ title }}
    </div>
    <el-row class="toalRow" :gutter="20" type="flex" justify="space-around">
      <el-col
        v-for="videoItem in videoData"
        :key="videoItem.id"
        :xl="4"
        :sm="6"
        :md="6"
        :lg="6"
        :offset="0"
      >
        <el-image
          @click="toVideo(videoItem.id)"
          class="toalCard"
          :src="videoItem.image"
          fit="fit"
        ></el-image>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getRandomVideo } from "../api/videoApi";
export default {
  props: {
    showTitle: {
      type: Boolean,
      default() {
        return false;
      },
    },
    title: {
      type: String,
      default() {
        return "为您推荐";
      },
    },
  },
  data() {
    return {
      videoData: [],
    };
  },
  computed: {
    // 响应式处理每行的视频数量
    showInLg() {
      return function (index) {
        return { "hidden-lg-and-down": index === 3 };
      };
    },
  },
  methods: {
    toVideo(id) {
      this.$router.push({
        name: "video",
        query: {
          id: id,
        },
      });
    },
    getRandomVideo() {
      getRandomVideo(4)
        .then((res) => {
          this.videoData = res.data.data.rows;
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },
  mounted() {
    this.getRandomVideo();
  },
};
</script>

<style lang="scss" scoped>
.video-list-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;

  .video-list-title {
    padding-left: 25px;
    margin: 10px 0 10px 0;
    font-size: 20px;
  }
}
.toalRow {
  width: 100%;
  height: 210px;
}

.toalCard {
  width: 280px;
  height: 210px;
}
</style>>
